<template>
  <el-dialog :title="!form.id ? '新增' : '修改'" :visible.sync="visible" :close-on-click-modal="false" width="40%" top="10vh">
    <div class="sketch_content">
      <el-form :model="form" label-width="120px" ref="dataForm">
        <el-form-item label="地区名称" prop="name" :rules="rules.isRange('1-64')">
          <el-input v-model="form.name" placeholder="请输入地区名称" maxlength="64" show-word-limit/>
        </el-form-item>
        <el-form-item label="显示顺序" prop="orderNum" :rules="rules.isInteger">
          <el-input v-model="form.orderNum" placeholder="请输入显示顺序"/>
        </el-form-item>
      </el-form>
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button size="small" icon="el-icon-close" @click.native="visible = false">取消</el-button>
      <el-button size="small" icon="el-icon-check" type="primary" :loading="isDisabled"
        @click.native="saveOrUpdate(form, '/sysRegion/save', '/sysRegion/update')">确定
      </el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        rules: this.getRules(),
        isDisabled: false,
        form: {
          name: '',
          parentId: '',
          orderNum: '',
          level: 1,
          flag: 1
        }
      }
    },
    methods: {
      init (id) {
        this.visible = true
        this.isDisabled = false
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
        })
        this.form.id = id
        if (id) {
          this.httpGet(`/sysRegion/info/${id}`).then(res => {
            this.form = res.data
          })
        } else {
        }
      }
    }
  }
</script>

